package com.ecarx.module_log.adapter;

import android.content.Context;
import android.text.TextPaint;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.ecarx.module_log.R;

import java.util.ArrayList;
import java.util.List;

public class TitleSpinnerAdapter extends ArrayAdapter<String> {

    private List<String> mList;
    private int topPadding, bottomPadding, rightPadding;

    public TitleSpinnerAdapter(Context context) {
        super(context, R.layout.item_title_spinner);
        this.mList = new ArrayList<>();
        topPadding = context.getResources().getDimensionPixelSize(R.dimen.dp_3);
        bottomPadding = context.getResources().getDimensionPixelSize(R.dimen.dp_3);
        rightPadding = context.getResources().getDimensionPixelSize(R.dimen.dp_10);
    }

    public void notifyData(List<String> logLevelList) {
        this.mList = logLevelList;
        notifyDataSetChanged();
    }


    @Override
    public int getCount() {
        if (mList == null) {
            return 0;
        }
        return mList.size();
    }

    @Override
    public String getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_title_spinner, parent, false);
        TextView textView = (TextView) view.findViewById(R.id.tv_name);
        String levelName = mList.get(position);
        TextPaint tp = textView.getPaint();
        tp.setFakeBoldText(true);
        textView.setText(levelName);
        textView.setPadding(0, topPadding,rightPadding,bottomPadding);
        return view;
    }
}
